<?php
/**
 * URL helper
 */
class Helper_FixUrl
{
    public $view;
    
    const MOD_REWRITE=1;
    
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }
    
    public function fixUrl($url='')
    {
        if ($url == '#') return $url;
        if (preg_match('/^http:\/\/.+/',$url)) return $url;
        
        $language=Zend_Registry::get('language');
        
        $lang_prefix=$language->getLocale() != $language->getDefaultLocale() ? $language->getLocale().'/' : '';
        
        if (!empty($lang_prefix) && empty($url)) $url='index';
        
        return self::MOD_REWRITE ? $this->view->baseUrl($lang_prefix.$url) : $this->view->baseUrl('index.php/'.$lang_prefix.$url);
    }
}
